package org.hit.burkun.network.tester;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;

import org.hit.burkun.file.FileHelper;
import org.hit.burkun.network.EdgeInfo;
import org.hit.burkun.network.SerializableGraph;
import org.hit.burkun.swalk.lap.SeribaleGraphAdpater;

public class LapcRandomWalkTester {
	
	static double salpha = 0.5;
	public static void main(String[] args) {
//		doTest8noScore();
//		caclc();
//		doTest9Score();
		doTest8Score();
	}
	
	
	public static void doTest9Score(){
		salpha = 0.8;
		double[] para = { 
				0.2991936430284393
				,0.32128074660016753
				,0.20581767459378736
				,-0.6969081100111801
				,-1.2055112569111912
				,-0.1266942224286071
				,-0.27018503998765503
				,-0.18773449777243384
				,0.13629878450697755
		};
		doPrWeightOpt(para);
		doPrWeightOptV(para);
	}
	
	public static void doTest8noScore(){
		//注意改变Adapter的特征提取函数
		
		double[] para = {1.765243156236959, 1.8023285977614363, 1.848247706695159 ,-3.4429622311927215 ,-1.0216921968658048 ,-2.0630209915674556, -1.3185980613606232, -2.6543338719590057, 0.04452188814495349 ,0.028617849276360532 }; 
		doPrWeightOpt(para);
//		doPrNoweight();
//		doPrWeight(8);
		doPrWeightOptV(para);
//		doPrNoweightV();
//		doPrWeightV(8);
		caclc();
	}
	
	public static void doTest8Score(){
		//注意改变Adapter的特征提取函数
		salpha = 0.1;
		double[] para = {
				0.6488039989157116
				,0.8476038724673189
				,0.8039127751877544
				,-0.389733987453398
				,-0.09196752696618109
				,-0.7556159270443441
				,-0.6193312480549625
				,-0.6846544146072754
		}; 
		doPrWeightOpt(para);
//		doPrNoweight();
//		doPrWeight(8);
		doPrWeightOptV(para);
//		doPrNoweightV();
//		doPrWeightV(8);
//		caclc();
	}
	
	
	public static void caclc(){
		System.out.println(ValidData.calcAuc("data/linkpredict/t-weigth-salpha-0.25-sample-1.0-opt.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/t-no-weigth-salpha-0.25-sample-1.0-noweight.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/t-weigth-salpha-0.25-sample-1.0-allone.txt"));
//		System.out.println(ValidData.calcAuc("data/pr2-wight-1.0.txt"));
		System.out.println(ValidData.calcAuc("data/linkpredict/v-weigth-salpha-0.25-sample-1.0-opt.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/v-no-weigth-salpha-0.25-sample-1.0-noweight.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/v-weigth-salpha-0.25-sample-1.0-allone.txt"));
	}
	
	public static void doPrNoweightV(){
		//删掉所有的，包括验证集合测试集
		//HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		//HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueValidObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseValidObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		double[] para = new double[]{1};
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, false);
		writeToFile("data/linkpredict/v-no-weigth-salpha-" + salpha + "-sample-1.0-noweight" +".txt", res);
		//writeToFile("data/linkpredict/v-no-weigth-salpha-" + salpha + "-sample-0.5-noweight" +".txt", res);

	}
	
	private static void writeToFile(String fileName, LinkedList<String> lines){
		FileHelper.writeFile(fileName, lines);
	}

	
	public static void doPrWeightV(int fnum){
//		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
//		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueValidObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseValidObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		double[] para = new double[fnum];
		for(int i=0; i < fnum; i++){
			para[i] = 1;
		}
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-1.0-allone" +".txt", res);
		//writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-0.5-allone" +".txt", res);
	}
	
	public static void doPrWeightOptV(double[] para){
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueValidObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseValidObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-1.0-opt" +".txt", res);
		//writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-0.5-opt" +".txt", res);
	}
	
	
	public static void doPrNoweight(){
		//删掉所有的，包括验证集合测试集
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		
		double[] para = new double[]{1};
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, false);
		writeToFile("data/linkpredict/t-no-weigth-salpha-" + salpha + "-sample-1.0-noweight" +".txt", res);
		//writeToFile("data/linkpredict/t-no-weigth-salpha-" + salpha + "-sample-0.5-noweight" +".txt", res);
	}
	
	
	public static void doPrWeight(int fnum){
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		
		double[] para = new double[fnum];
		for(int i=0; i < fnum; i++){
			para[i] = 1;
		}
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-1.0-allone" +".txt", res);
		//writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-0.5-allone" +".txt", res);
	}
	
	public static void doPrWeightOpt(double[] para){
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-1.0-opt" +".txt", res);
		//writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-0.5-opt" +".txt", res);
	}
	
}
